<script>
	// 解决小数点失针
	//四则运算化成整数计算方法
	    var floatCalc = function (a, b) {
	        a = a + '', b = b + '';
	        var aNum = a.indexOf('.'),
	            bNum = b.indexOf('.'),
	            aSum,
	            bSum,
	            resultNum,
	            inta,
	            intb;
	 
	        aSum = aNum < 0 ? 0 : a.split('.')[1].length;
	        bSum = bNum < 0 ? 0 : b.split('.')[1].length;
	        resultNum = aSum > bSum ? aSum : bSum;
	 
	        inta = aNum < 0 ? Number(a + (Math.pow(10, resultNum) + '').replace('1', '')) : (function () {
	            a = a.replace('.', '');
	            a = resultNum == aSum ? a : a + (Math.pow(10, resultNum - aSum) + '').replace('1', '');
	            return Number(a);
	        }())
	 
	        intb = bNum < 0 ? Number(b + (Math.pow(10, resultNum) + '').replace('1', '')) : (function () {
	            b = b.replace('.', '');
	            b = resultNum == bSum ? b : b + (Math.pow(10, resultNum - bSum) + '').replace('1', '');
	            return Number(b);
	        }())
	 
	        return {
	            a: inta,
	            b: intb,
	            num: resultNum
	        };
	    }
	    //加法
	    Number.prototype.add = function (n) {
	        var o = floatCalc(this, n);
	        return (o.a + o.b) / Math.pow(10, o.num);
	    }
	    //减法
	    Number.prototype.minus = function (n) {
	        var o = floatCalc(this, n);
	        return (o.a - o.b) / Math.pow(10, o.num);
	    }
	    //乘法
	    Number.prototype.subtract = function (n) {
	        var o = floatCalc(this, n);
	        return (o.a * o.b) / Math.pow(10, o.num * 2);
	    }
	    //除法
	    Number.prototype.divide = function (n) {
	        var o = floatCalc(this, n);
	        return (o.a / o.b);
	    }
	import { mapMutations } from 'vuex'
    export default {
        onLaunch: function() {
            // console.log('App Launch');
            // #ifdef APP-PLUS
            // App平台检测升级，服务端代码是通过uniCloud的云函数实现的，详情可参考：https://ext.dcloud.net.cn/plugin?id=2226
			if(plus.runtime.appid !== 'HBuilder'){ // 真机运行不需要检查更新，真机运行时appid固定为'HBuilder'，这是调试基座的appid
				uni.request({
				    url: 'https://7a3e3fa9-7820-41d0-be80-11927ac2026c.bspapp.com/http/update', //检查更新的服务器地址
				    data: {
				        appid: plus.runtime.appid,
				        version: plus.runtime.version,
				        imei: plus.device.imei
				    },
				    success: (res) => {
				        if (res.statusCode == 200 && res.data.isUpdate) {
				            // 提醒用户更新
				            uni.showModal({
				                title: '更新提示',
				                content: res.data.note ? res.data.note : '是否选择更新',
				                success: (ee) => {
				                    if (ee.confirm) {
				                        plus.runtime.openURL(res.data.url);
				                    }
				                }
				            })
				        }
				    }
				})
			}

			// 一键登录预登陆，可以显著提高登录速度
			// uni.preLogin({
			// 	provider: 'univerify',
			// 	success: (res) => {
			// 		// 成功
			// 		this.setUniverifyErrorMsg();
			// 		console.log("preLogin success: ", res);
			// 	},
			// 	fail: (res) => {
			// 		this.setUniverifyLogin(false);
			// 		this.setUniverifyErrorMsg(res.errMsg);
			// 		// 失败
			// 		console.log("preLogin fail res: ", res);
			// 	}
			// })
            // #endif
        },
        onShow: function() {
            console.log('App Show')
        },
        onHide: function() {
            console.log('App Hide')
        },
		globalData: {
			test: ''
		},
		methods:{
			...mapMutations(['setUniverifyErrorMsg','setUniverifyLogin'])
		}
    }
</script>

<style>
    /* #ifndef APP-PLUS-NVUE */
    /* uni.css - 通用组件、模板样式库，可以当作一套ui库应用 */
	/* H5 兼容 pc 所需 */
	/* #ifdef H5 */
	@media screen and (min-width: 768px) {
		body{
			overflow-y: scroll;
		}
	}
	
	 /* 顶栏通栏样式 */
	/* .uni-top-window {
	    left: 0;
	    right: 0;
	} */

	uni-page-body {
		background-color: #F5F5F5 !important;
		min-height: 100% !important;
		height: auto !important;
	}

	.uni-top-window uni-tabbar .uni-tabbar {
		background-color: #fff !important;
	}

	.uni-app--showleftwindow .hideOnPc {
		display: none !important;
	}
	/* #endif */

    /* 以下样式用于 hello uni-app 演示所需 */
    page {
        background-color: #efeff4;
        height: 100%;
        font-size: 28rpx;
        line-height: 1.8;
    }
	.fix-pc-padding {
		padding: 0 50px;
	}
    .uni-header-logo {
        padding: 30rpx;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-top: 10rpx;
    }

    .uni-header-image {
        width: 100px;
        height: 100px;
    }

    .uni-hello-text {
        color: #7A7E83;
    }

    .uni-hello-addfile {
        text-align: center;
        line-height: 300rpx;
        background: #FFF;
        padding: 50rpx;
        margin-top: 10px;
        font-size: 38rpx;
        color: #808080;
    }
    /* #endif*/
</style>
